<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
	 <form id="ligerForm" >
			<div class="fieldset1 tabel_col clearFix">
				<div class="caption">
					<span class="title">移交申请</span>
				</div>
				<div class="fieldBox col_100"></div>
			</div>
			<div class="fieldset1 tabel_col clearFix">
				<!-- 移交申请列表显示块 -->
				<div class="caption">
					<span class="title">权证资料</span>
					<span>支付表号 ${paySchNo}</span>
				</div>
				<div class="fieldBox col_100">
					<div class="sqPanel">
							<div id="detailGrid">
								<div id="ligergrid_warrant" class="sq-grid"></div>
							</div>
						</div>
				</div>
			</div>
		<div class="fieldset1 tabel_col clearFix">
			<div class="caption">
				<span class="title">接收人信息</span>
			</div>
			<div class="fieldBox col_50">
						<div class="label">工号/姓名</div>
						<div class="field">
							<input id="jobNum"  name="jobNum"   type="text"   class="ui-textbox"  ligerui="width: 160"
								value=""    />
							<a class="sq-button-hasicon" href="javascript:getSysUsr()"><i class="sqBtnIco_4"></i>查找收件人</a>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">收件人（工号）</div>
						<div class="field">
							<input id="idCard"  name="arcPostInfoVO.idCard"  type="text"   class="ui-textbox"  ligerui="width: 160"  disabled="disabled"  />
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">收件人（姓名）</div>
						<div class="field">
							<input id="recipient"  name="arcPostInfoVO.recipient"  type="text"   class="ui-textbox"  ligerui="width: 160"   disabled="disabled"  />
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">联系电话</div>
						<div class="field">
							<input id="mobile"  name="arcPostInfoVO.mobile"  type="text"   class="ui-textbox"  ligerui="width: 160" 
								value=""   validate="{mobile:true}" />
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">接收方式</div>
						<div class="field">
							<select id="sendType"  name="arcPostInfoVO.sendType"  ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${sendTypeList}" var="item">
										<option value="${item.key}">${item.value}</option>
									</c:forEach>
								</select>
						</div>
					</div>
					<div id="emailInfo" style="display: none;">
						<div class="fieldBox col_50">
							<div class="label">快递公司</div>
							<div class="field">
								<select id="sendCompany"  name="arcPostInfoVO.sendCompany"  ligerui="width: 160" >
										<option value="">请选择</option>
										<c:forEach items="${sendCompanyList}" var="item">
											<option value="${item.key}">${item.value}</option>
										</c:forEach>
									</select>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">快递单号</div>
							<div class="field">
								<input id="sendNum"  name="arcPostInfoVO.sendNum"  type="text"   class="ui-textbox"  ligerui="width: 160" 
									value=""    />
							</div>
						</div>
						<div class="fieldBox col_100">
							<div class="label">邮寄地址</div>
							<div class="field">
							<input id="sendAddr"  name="arcPostInfoVO.sendAddr"  type="text"   class="ui-textbox"  
								value=""    />
						</div>
						</div>
					</div>
				   <div class="fieldBox col_100">
						<div class="label">备注</div>
						<div class="field">
							 <textarea id="remark"  name="arcPostInfoVO.remark" rows="3" class="l-textarea" style="width:80%"></textarea>
						</div>
					</div>
					<!-- 隐藏参数 -->
	                <div class="fieldBox col_100" style="display:none;">
						<div class="field">
							<input type="text" id="isGrpBiz" name="isGrpBiz" value="${isGrpBiz}"></span>		<!--hidde date 是否团单  -->
	                        <input name="contractNo" id="contractNo" type="text" class="ui-textbox" value='${contractNo}'>
	                        <input name="payListCode" id="payListCode" type="text" class="ui-textbox" value='${paySchNo}'>
	                         <input name="arcReceiptMainId" id="arcReceiptMainId" type="text" class="ui-textbox" value='${arcMgrMainVO.arcReceiptMainId}'>
	                         <input name="prdStsCd" id="prdStsCd" type="text" class="ui-textbox" value='${prdStsCd}'>
	                         <input name="cstId" id="cstId" type="text" class="ui-textbox"  value='${cstId}'>
	                         <input name="paySchId" id="paySchId" type="text" class="ui-textbox"  value='${paySchId}'>
	                    </div>
	                </div>
		</div>
		<div class="btnsBox">
			<span id="saveBtn" class="sq-button sq-button-round" onclick="transferApplyStart();">发起移交</span>
			<span id="closeBtn" class="sq-button sq-button-round" onclick="Remove_navTab();">取消</span>
					
		</div>	
	</form>		
	</div>
<script type="text/javascript">
//var  arcMgrDetailList = "${arcMgrMainVO.arcMgrDetailList}";//多个支付表号
var grid2 = null;
$(function() {
	//$("#ligerForm").ligerForm();
	$("#ligerForm").ligerForm({
        validate : true
    });
	 initWarrantGrid();//初始化权证资料
	 //initSettleGrid();//初始化结清资料
	$("#sendType").change(function(){
		if(this.value!= "" && this.value == 0) {//邮寄
			$("#emailInfo").show();
		}else {
			$("#emailInfo").hide();
		}
	});
});
//查找收件人 
function getSysUsr(){
	
	if($.trim($("#jobNum").val()) == ""){
		$.ligerDialog.SQalert({content: "请填写工号/姓名",SQ_type: "warning"});
		return;
	}
	var ligerForm = liger.get("ligerForm");
	if (!ligerForm.valid()) {
	    	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning",SQ_showButtons: true});
            return false ; 
     }
		
	 $.ajax({
		type: 'get',
		dataType:'json',
		url: '<%=path%>/archive/arcTransferMain/getSysUsr.do?jobNum='+$("#jobNum").val(),
		success:function(msg){
			//console.log(msg);
			 if(msg.success == 1){
				 if(msg.data){
					 $("#idCard").val(msg.data.usrNm);
					 $("#recipient").val(msg.data.refRlNm);
					 $("#mobile").val(msg.data.mp);
				 }else{
					 $.ligerDialog.SQalert({content:"没有查询到对应人员", SQ_type: "warning"});
					 $("#idCard").val("");
					 $("#recipient").val("");
					 $("#mobile").val("");
				 }
			 }else{
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
			 }
		}
	}); 
}
//发移交申请
function transferApplyStart(){
	var ligerForm = liger.get("ligerForm");
	//1 核查该支付表下有未归还权证资料，请先结束流程
	var isNot=false;//BORROW_STATUS=0 未借阅 已存档 BORROW_STATUS=1 借出 BORROW_STATUS=2借出不用归还
	initWarrantGrid();//初始化权证资料
	var warrantJson=grid2.getData();
	for(var p in warrantJson){//遍历json数组时，这么写p为索引，0,1
	   // alert(warrantJson[p].id + " " + warrantJson[p].borrowStatus);
		if(warrantJson[p].borrowStatus=='1'){
			isNot=true;
		}
	}
	if(isNot){
		$.ligerDialog.SQalert({content: "该支付表下有未归还权证资料，请先结束流程",SQ_type: "warning"});
		return ;
	}
	
	var re=jycheck();//校验客户是否有小贷
	if(re==1){
	}else{
		$.ligerDialog.SQalert({content: "该客户有小贷未结清，无法申请权证移交，请先结清小贷",SQ_type: "warning"});
		return ;
	}
	
	//2检查邮寄信息
	if($.trim($("#idCard").val()) == ""){
			$.ligerDialog.SQalert({content: "输入工号，点击'查找收件人'，查询出收件人（工号）和收件人（姓名）",SQ_type: "warning"});
			return ;
	} 
   if($.trim($("#mobile").val()) == ""){
		$.ligerDialog.SQalert({content: "请填写联系电话",SQ_type: "warning"});
		return ;
	} 
   if($.trim($("#sendType").val()) == ""){
		$.ligerDialog.SQalert({content: "请选择接收方式",SQ_type: "warning",SQ_showButtons: true});
		return ;
	}
   if($.trim($("#sendType").val()) == 0){
	   if($.trim($("#sendCompany").val()) == ""){
			$.ligerDialog.SQalert({content: "请选择快递公司",SQ_type: "warning",SQ_showButtons: true});
			return ;
		} 
	   if($.trim($("#sendNum").val()) == ""){
			$.ligerDialog.SQalert({content: "请输入快递单号",SQ_type: "warning",SQ_showButtons: true});
			return ;
		}
	   if($.trim($("#sendAddr").val()) == ""){
			$.ligerDialog.SQalert({content: "请输入邮寄地址",SQ_type: "warning",SQ_showButtons: true});
			return ;
		}
	}
   
   
	//3 、组织数据
	var data = ligerForm.getData();
	data["contractNo"] ='${contractNo}';
	data["paySchNo"] ='${paySchNo}';
	data["prdStsCd"] ='${prdStsCd}';
	data["bizTypCd"]='${bizTypCd}';
	data["buOrgCd"]='${buOrgCd}';
	data["cstNm"]='${cstNm}';
	//data["_arcTransferDetailList"] =JSON.stringify(grid3.getData());
	//data["arcReceiptMainId"] = '${arcMgrMainVO.arcReceiptMainId}';//交接单ID
	//data["arcReceiptName"] = '${arcMgrMainVO.arcReceiptName}';//交接单名称
	//data["versioni"] = '${arcMgrMainVO.versioni}';//交接单版本号
	data["portfolioNumber"] = '${arcMgrMainVO.portfolioNumber}';//总公司档案袋编号
	data["portfolioNumberProvince"] = '${arcMgrMainVO.portfolioNumberProvince}';//省公司档案袋编号
	data["IS_GRP_BIZ"]='${isGrpBiz}';//是否团单
	data["arcMgrMainId"]='${arcMgrMainVO.id}';//档案管理主表id
	//console.log(data);
	//return;
	
	var wait_dialog = null;
	$.ajax({
		type: 'post',
		dataType: 'json',
		data: data,
		url: '<%=path%>/archive/arcTransferMain/transferApplyStart.do?',
		beforeSend: function(){
			wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting"});
		},success:function(msg){
			wait_dialog.close();
			if(msg.success == 1){
					//$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
					alert(msg.info);
					Remove_navTab();//关闭当前页面
			}else{
				$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			}
		},error:function (XMLHttpRequest, textStatus, errorThrown) { 
			wait_dialog.close();
			$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
		} 
	});
}
//初始化权证资料列表
function initWarrantGrid(){
	var contractNo = $("#contractNo").val();
	var payListCode = $("#payListCode").val();
	$("#ligergrid_warrant").ligerGrid({
		url:'<%=path%>/archive/arcTransferMain/initGridList.do',
		method:'get',
		parms:{contractNo: contractNo, payListCode: payListCode, arcLevel: "2",fileFlag:"3"},
		columns:[
			{ display: '权证类别', name: 'fileFlagNm', minWidth: 150, align: 'center', enabledSort: true},
			{ display: '权证名称', name: 'fileName', minWidth: 180, align: 'center', enabledSort: true},
			{ display: '资料类型', name: 'dossierTempNm', minWidth: 160, align: 'center', enabledSort: true},
			{ display: '存档份数', name: 'dossierCountT', minWidth: 160, align: 'center', enabledSort: true},
			{ display: '已移交份数', name: 'transferCount', width: 90, align: 'center', enabledSort: true,
				render:function (rowdata, rowindex, value){
					return "<span>"+0+"</span>";
				}
			}
		],
		//pageSize:10,
		usePager: false,//是否有分页便签
		root:'rows',
		record:'total',
		hideLoadButton:false,
		width:'100%',
		heightDiff:-2,
		enabledEdit: true,
		checkbox:false,//列表是否有选择框
		rownumbers:true//列表是否有行号
	});
	grid2 = liger.get("ligergrid_warrant");
}
//校验是否小贷
function   jycheck(){
	// Code: 0 失败  1 成功
	var re=0;
	var paySchId=$('#paySchId').val();
	var cstId=$('#cstId').val();
	$.ajax({
		type: 'post',
		dataType: 'json',
		async:false,
		data: {'paySchId':paySchId,'cstId':cstId},
		url: '<%=path%>/archive/arcTransferMain/checkSmallLoan.do?',
		beforeSend: function(){
			wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting"});
		},success:function(msg){
			wait_dialog.close();
			if(msg.data == 1){
				re=1;
			}else{
				$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			}
		},error:function (XMLHttpRequest, textStatus, errorThrown) { 
			wait_dialog.close();
			$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
		} 
	});
	return re;
}
 
</script>
</body>
</html>
